473,544 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

display data with php and then sort with JSON

realin
254 Contributor
hiya guys,

Its been long i came here to discuss my problems. Hoep everything is same and i am gonna get quick reply :D

Well i have certain static data which i need to display using FastTemplate and then i want to use JSON to sort that data on the client side.

I wish i could do it with simple ajax, but i have to do it using json only as it has to be client side sorting for performance issues. For example i have this array, how do i do it, i am kinda stuck, just a little Hint would do ..

[PHP]$websiteTools=a rray(

0=> array('title'=> 'Browser Plugin',
'desc'=>'descri ption',
'thumb'=>'http://',
'link'=>'http://',
'popular'=>'1',
'timestamp'=>ti me(),
'weight'=>'225k b',
'category'=>'to ols'
),
1=>array('title '=>'XML RSS Feed',
'desc'=>'Descri ption',
'thumb'=>'http://',
'link'=>'http://',
'popular'=>'2',
'timestamp'=>ti me(),
'weight'=>'215k b',
'category'=>'to ols'
)
);[/PHP]

thanks in advance..
regards
Realin !
Nov 6 '08 #1
5 4580
acoder
16,027 Recognized Expert Moderator MVP
So you want to generate JSON using PHP?
Nov 6 '08 #2
realin
254 Contributor
Of course generating JSON is the part of problem and that can be done using json_encode() method of php. But how do i transfer it to client side and then use json to sort the divs based on div ids or may be anyother sorting element. As if now i simply want to display this array on a HTML page, may be using JSON.

cheers !!
Realin !
Nov 7 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
To "transfer" it to the client-side, just use PHP to set the JSON to a JavaScript variable:
Expand|Select|Wrap|Line Numbers
  1. var json = <?php ... ?>;
Nov 7 '08 #4
rnd me
427 Recognized Expert Contributor
Arrays can be sorted using the ([1,5,2,3]).sort() method.

if you need to sort an array of objects, you will have to write a custom sort function.

see http://www.breakingpar .com/bkp/home.nsf/0/87256B280015193 F87256C8D00514F A4 for more about that

you pass the actual data using JSONP, and you callback build the HTML from the data and sets the .innerHTML of a container div, or add the elements programatically though the DOM.
Nov 7 '08 #5
realin
254 Contributor
thanks a lot guys..
will try and revert..
Nov 7 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

22
5597
by: googlegroups | last post by:
I am playing with the XMLHTTPRequest method to perform client/server transactions. I have it set up right now so that when readyState is 4, it takes the XML and processes it. This works great until there is alot of data. In that case, the user will have to wait for the data to come back which may take a minute or so. I don't want the user...
20
6815
by: Luke Matuszewski | last post by:
Welcome As suggested i looked into JSON project and was amazed but... What about cyclical data structures - anybody was faced it in some project ? Is there any satisactional recomendation... PS i am ready to use JSON as data/object interchange when using AJAX and my J2EE project - because it is easier to traverse the JavaScript object...
3
3892
by: Rich | last post by:
Hi, I'm very, very new to javascript, so please bear with me if this is a silly question. My problem is this. I would like to some javascript connect to a URL on the same webserver and read a CGI. The output from this CGI is not plain HTML but rather data which needs to be displayed in a moving graph. Coming from a Perl
3
2242
by: kpmassey | last post by:
I'm using javascript to construct large tables from an array of data, using ideas from: http://www.oreillynet.com/pub/a/javascript/2003/05/06/dannygoodman.html The data itself cannot be constructed by the javascript code, so is explicitly passed in with a large array, e.g. var data = new Array();
3
2280
by: xhe | last post by:
I found Jason is a very handy data format for client/server communication. But I just met a problem as follows: I want to read the data replied from server in Jason format, the reply is like this: it is generated automatically by amfphp1.9 from an array. I used Ajax to call a method, and the server code replied an array in the above
6
2387
by: Jasper | last post by:
Hi, Maybe this is off-topic, but perhaps you can help. I'm looking for ideas on how to parse a data file. I dont know XML but I know it parses data in text format. I have a structured data file of the general form shown below. I dont have any definition of the data. Basically it looks like it is hierarchical, token/data pairs defined by...
4
3989
by: avicalc | last post by:
I need help with the structure of a JavaScript program. My process is as follows: 1) Get JSON data via XMLHttpRequest. 2) When done with the above, process the JSON data which may take up to 3 seconds. 3) Because of the possibility of a time consuming operation, display a simple animation ("Loading...", etc) while the user is waiting. ...
3
1064
by: Steve Potter | last post by:
I'm working on a project to create a central administration interface for several websites located on different physical servers. You can think of the websites as a blog type application. My administration application will be used to create new blog posts with associated media (images, etc..) So I am thinking to setting up a script on...
0
2478
by: JonTwend | last post by:
I am working with the Twitter API and finding it great fun and generally easy to use. But I am having trouble getting to the data in the trends/current.json file. I am able to loop through the object data with a foreach loop and print it out. But I want to do more with the data than just print it. Just to be clear, I want to work with the...
0
7642
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7405
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7737
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5950
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5316
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4938
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3432
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
688
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.